<template>
  <view>
    <view class="" v-if="JSON.stringify(address)=='{}'">
      <button type="primary" size="mini" class="btnChooseAddress" @click="chooseAddress">请选择收货地址+</button>
    </view>
    <!-- 收获地址区域-->
    <view class="address-box" v-else>
      <view class="address-item-top">
        <view class="address-name">
          收货人：{{address.userName}}
        </view>
        <view class="address-phone">
          <view class="phone">{{address.telNumber}}</view>
          <uni-icons type="arrowright" size="16"></uni-icons>
        </view>
      </view>
      <view class="address-item-bottom">
        收货地址：{{addstr}}
      </view>
    </view>
    <!-- 底部的边框线 -->
      <image src="/static/cart_border@2x.png" class="address-border"></image>
  </view>
</template>

<script>
  import {mapState,mapMutations,mapGetters} from 'vuex'
  export default {
    name:"my-address",
    data() {
      return {
        
      };
    },
    computed:{
      ...mapState('m_user',['address']),
      ...mapGetters('m_user',['addstr']),
      // addstr(){ 
      //   if(!this.address.userName) return ''
      //   // 拼接 省，市，区，详细地址 的字符串并返回给用户
      //   return this.address.provinceName + this.address.cityName + this.address.countyName + this.address.detailInfo
      // }
    },
    methods:{
      ...mapMutations('m_user',['updateAddress']),
      //获取地址
      chooseAddress(){
        uni.chooseAddress({
          success:(e) =>{
            this.updateAddress(e)
          }
        })
        
      },
    }
  }
</script>

<style lang="scss">
.address-box{
  margin: 20px 10px 10px 10px;
  font-size: 13px;
  .address-item-top{
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
    .address-phone{
      display: flex;
      // margin: auto 0;
    }
  }
  .address-item-bottom{
    margin-top: 7px;
    height: 25px;
    width: 100%;
    flex-wrap: wrap;
  }
}
.address-border{
  width: 100%;
  height: 5px;
}
</style>